﻿/*
 * Copyright (C) 2012 TheLionsRoar <thelionwillalwaysroar@gmail.com>
 * Copyright (C) 2012 Jedrix <jedrix2454@gmail.com>
 * 
 * This file is part of the LEO Game Library.
 * 
 * LEO is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 * 
 * LEO is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
 * GNU General Public License for more details.
 * 
 * You should have receieved a copy of the GNU General Public License
 * along with LEO. If not, see <http://www.gnu.org/licenses/>.
 */
using System;
using System.Collections.Generic;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;

namespace LEO.Framework {
    public class Sprite : Element {
        private Dictionary<string, Animation> animations;
        private string currentAnimation;
        private bool isAnimating = false;
        private Texture2D texture;

        public Dictionary<string, Animation> Animations {
            get { return animations; }
            set { animations = value; }
        }

        public string CurrentAnimation {
            get { return currentAnimation; }
            set { currentAnimation = value; }
        }

        public bool IsAnimating {
            get { return isAnimating; }
            set { isAnimating = value; }
        }

        public int Width {
            get { return animations[currentAnimation].FrameWidth; }
        }

        public int Height {
            get { return animations[currentAnimation].FrameHeight; }
        }

        public Sprite(Texture2D sprite, Dictionary<string, Animation> animation) {
            texture = sprite;
            animations = animation;
        }

        public override void Update(GameTime gameTime) {
            if(isAnimating && currentAnimation != null) {
                animations[currentAnimation].Update(gameTime);
            }

            base.Update(gameTime);
        }

        public void Draw(SpriteBatch spriteBatch, Vector2 position) {
            if(currentAnimation != null) {
                spriteBatch.Draw(texture, position, animations[currentAnimation].CurrentFrameRect, Color.White);
            }
        }
    }
}
